<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
          "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<title>QUnit for ASN1 Encoder Class 'asn1cms.js'</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="qunit.js"></script>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />

<script src="../ext/cj/cryptojs-312-core-fix.js"></script>
<script src="../ext/cj/x64-core.js"></script>
<script src="../ext/cj/cipher-core_min.js"></script>
<script src="../ext/cj/aes_min.js"></script>
<script src="../ext/cj/tripledes_min.js"></script>
<script src="../ext/cj/enc-base64_min.js"></script>
<script src="../ext/cj/md5_min.js"></script>
<script src="../ext/cj/sha1_min.js"></script>
<script src="../ext/cj/sha256_min.js"></script>
<script src="../ext/cj/sha224_min.js"></script>
<script src="../ext/cj/sha512_min.js"></script>
<script src="../ext/cj/sha384_min.js"></script>
<script src="../ext/cj/ripemd160_min.js"></script>
<script src="../ext/cj/hmac_min.js"></script>
<script src="../ext/cj/pbkdf2_min.js"></script>


<script src="../ext/jsbn.js"></script>
<script src="../ext/jsbn2.js"></script>
<script src="../ext/prng4.js"></script>
<script src="../ext/rng.js"></script>
<script src="../ext/rsa.js"></script>
<script src="../ext/rsa2.js"></script>
<script src="../ext/base64.js"></script>
<script src="../ext/ec.js"></script>
<script src="../ext/ec-patch.js"></script>

<script src="../src/base64x-1.1.js"></script>
<script src="../src/asn1hex-1.1.js"></script>
<script src="../src/rsapem-1.1.js"></script>
<script src="../src/rsasign-1.2.js"></script>
<script src="../src/crypto-1.1.js"></script>
<script src="../src/keyutil-1.0.js"></script>
<script src="../src/asn1-1.0.js"></script>
<script src="../src/asn1x509-1.0.js"></script>
<script src="../src/asn1cms-1.0.js"></script>
<script src="../src/asn1cades-1.0.js"></script>
<script src="../src/x509-1.1.js"></script>
<script src="../src/ecdsa-modified-1.0.js"></script>
<script src="../src/ecparam-1.0.js"></script>
<script src="../src/dsa-2.0.js"></script>

<script type="text/javascript">
<!--
$(document).ready(function(){

// _test/z4.* RSA 2048bit
var sZ4_PRVP8PPEM = (function() {/*
-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDfdOqotHd55SYO
0dLz2oXengw/tZ+q3ZmOPeVmMuOMIYO/Cv1wk2U0OK4pug4OBSJPhl09Zs6IwB8N
wPOU7EDTgMOcQUYB/6QNCI1J7Zm2oLtuchzz4pIb+o4ZAhVprLhRyvqi8OTKQ7kf
Gfs5Tuwmn1M/0fQkfzMxADpjOKNgf0uy6lN6utjdTrPKKFUQNdc6/Ty8EeTnQEwU
lsT2LAXCfEKxTn5RlRljDztS7Sfgs8VL0FPy1Qi8B+dFcgRYKFrcpsVaZ1lBmXKs
XDRu5QR/Rg3f9DRq4GR1sNH8RLY9uApMl2SNz+sR4zRPG85R/se5Q06Gu0BUQ3UP
m67ETVZLAgMBAAECggEADjU54mYvHpICXHjc5+JiFqiH8NkUgOG8LL4kwt3DeBp9
bP0+5hSJH8vmzwJkeGG9L79EWG4b/bfxgYdeNX7cFFagmWPRFrlxbd64VRYFawZH
RJt+2cbzMVI6DL8EK4bu5Ux5qTiV44Jw19hoD9nDzCTfPzSTSGrKD3iLPdnREYaI
GDVxcjBv3Tx6rrv3Z2lhHHKhEHb0RRjATcjAVKV9NZhMajJ4l9pqJ3A4IQrCBl95
ux6Xm1oXP0i6aR78cjchsCpcMXdP3WMsvHgTlsZT0RZLFHrvkiNHlPiil4G2/eHk
wvT//CrcbO6SmI/zCtMmypuHJqcr+Xb7GPJoa64WoQKBgQDwrfelf3Rdfo9kaK/b
rBmbu1++qWpYVPTedQy84DK2p3GE7YfKyI+fhbnw5ol3W1jjfvZCmK/p6eZR4jgy
J0KJ76z53T8HoDTF+FTkR55oM3TEM46XzI36RppWP1vgcNHdz3U4DAqkMlAh4lVm
3GiKPGX5JHHe7tWz/uZ55Kk58QKBgQDtrkqdSzWlOjvYD4mq4m8jPgS7v3hiHd+1
OT8S37zdoT8VVzo2T4SF+fBhI2lWYzpQp2sCjLmCwK9k/Gur55H2kTBTwzlQ6WSL
Te9Zj+eoMGklIirA+8YdQHXrO+CCw9BTJAF+c3c3xeUOLXafzyW29bASGfUtA7Ax
QAsR+Rr3+wKBgAwfZxrh6ZWP+17+WuVArOWIMZFj7SRX2yGdWa/lxwgmNPSSFkXj
hkBttujoY8IsSrTivzqpgCrTCjPTpir4iURzWw4W08bpjd7u3C/HX7Y16Uq8ohEJ
T5lslveDJ3iNljSK74eMK7kLg7fBM7YDogxccHJ1IHsvInp3e1pmZxOxAoGAO+bS
TUQ4N/UuQezgkF3TDrnBraO67leDGwRbfiE/U0ghQvqh5DA0QSPVzlWDZc9KUitv
j8vxsR9o1PW9GS0an17GJEYuetLnkShKK3NWOhBBX6d1yP9rVdH6JhgIJEy/g0Su
z7TAFiFc8i7JF8u4QJ05C8bZAMhOLotqftQeVOMCgYAid8aaRvaM2Q8a42Jn6ZTT
5ms6AvNr98sv0StnfmNQ+EYXN0bEk2huSW+w2hN34TYYBTjViQmHbhudwwu8lVjE
ccDmIXsUFbHVK+kTIpWGGchy5cYPs3k9s1nMR2av0Lojtw9WRY76xRXvN8W6R7Eh
wA2ax3+gEEYpGhjM/lO2Lg==
-----END PRIVATE KEY-----
*/}).toString().match(/\/\*([^]*)\*\//)[1];

var sZ4_CERPEM = (function() {/*
-----BEGIN CERTIFICATE-----
MIIC/zCCAeegAwIBAgIBATANBgkqhkiG9w0BAQUFADAaMQswCQYDVQQGEwJVUzEL
MAkGA1UECgwCWjQwHhcNMTMwODI4MTgyODM0WhcNMjMwODI4MTgyODM0WjAaMQsw
CQYDVQQGEwJVUzELMAkGA1UECgwCWjQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
ggEKAoIBAQDfdOqotHd55SYO0dLz2oXengw/tZ+q3ZmOPeVmMuOMIYO/Cv1wk2U0
OK4pug4OBSJPhl09Zs6IwB8NwPOU7EDTgMOcQUYB/6QNCI1J7Zm2oLtuchzz4pIb
+o4ZAhVprLhRyvqi8OTKQ7kfGfs5Tuwmn1M/0fQkfzMxADpjOKNgf0uy6lN6utjd
TrPKKFUQNdc6/Ty8EeTnQEwUlsT2LAXCfEKxTn5RlRljDztS7Sfgs8VL0FPy1Qi8
B+dFcgRYKFrcpsVaZ1lBmXKsXDRu5QR/Rg3f9DRq4GR1sNH8RLY9uApMl2SNz+sR
4zRPG85R/se5Q06Gu0BUQ3UPm67ETVZLAgMBAAGjUDBOMB0GA1UdDgQWBBQHZPTE
yQVu/0I/3QWhlTyW7WoTzTAfBgNVHSMEGDAWgBQHZPTEyQVu/0I/3QWhlTyW7WoT
zTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4IBAQDHxqJ9y8alTH7agVMW
Zfic/RbrdvHwyq+IOrgDToqyo0w+IZ6BCn9vjv5iuhqu4ForOWDAFpQKZW0DLBJE
Qy/7/0+9pk2DPhK1XzdOovlSrkRt+GcEpGnUXnzACXDBbO0+Wrk+hcjEkQRRK1bW
2rknARIEJG9GS+pShP9Bq/0BmNsMepdNcBa0z3a5B0fzFyCQoUlX6RTqxRw1h1Qt
5F00pfsp7SjXVIvYcewHaNASbto1n5hrSz1VY9hLba11ivL1N4WoWbmzAL6BWabs
C2D/MenST2/X6hTKyGXpg3Eg2h3iLvUtwcNny0hRKstc73Jl9xR3qXfXKJH0ThTl
q0gq
-----END CERTIFICATE-----
*/}).toString().match(/\/\*([^]*)\*\//)[1];

// sample_node/_dev/z3.p7s
var hZ3P7S = "308203ce06092a864886f70d010702a08203bf308203bb020101310f300d06096086480165030402010500301206092a864886f70d010701a0050403616161a08201fe308201fa30820163a003020102020101300d06092a864886f70d01010b0500301a310b3009060355040613024a50310b3009060355040a0c025a33301e170d3137303732393036343530345a170d3237303732393036343530345a301a310b3009060355040613024a50310b3009060355040a0c025a3330819f300d06092a864886f70d010101050003818d0030818902818100b0e290513164c116e5bc2c8fd0dc90403e022ee361eefe227e541e9b2a09aa9794f949405a738835831e9d4895623aafe9d9ffb009852df2eb06d5ac5f08378a2129a81ad4b20bdd10df9c66e6e10705d3aaeb134bc790c00b52ed28ffbce6474a9481e367461776d49ffee6fb7d9f36da8a09258215b70ca60269937f9f709b0203010001a350304e301d0603551d0e0416041443983bc00d44b24fa6232c1f39953af0d10d86e7301f0603551d2304183016801443983bc00d44b24fa6232c1f39953af0d10d86e7300c0603551d13040530030101ff300d06092a864886f70d01010b0500038181001d8f34075272864de4616725ce0f9f27fd0cbfebe311d32036603ee996c7146a4ef6424c2f4d57610e92f119d45108817849f2d5f520fa7265057d4e1f1cf8fb43496ab35e9a3df61ab8214178505875b4dd17c8d99df8f01ff12101261e1a711c59eeab961681593ebfc8cee186bb8d12865efc09f4b9d586efcca7c1e5ea913182018d30820189020101301f301a310b3009060355040613024a50310b3009060355040a0c025a33020101300d06096086480165030402010500a081c1301806092a864886f70d010903310b06092a864886f70d010701301c06092a864886f70d010905310f170d3137303732393036353831385a302f06092a864886f70d010904312204209834876dcfb05cb167a5c24953eba58c4ac89b1adf57f28f2f9d09af107ee8f03056060b2a864886f70d010910022f31473045304304201608f73494d0e6bbda3432da2b920045fae20d0b2ad45d73f8a11cdfe5d44aa7301f301a310b3009060355040613024a50310b3009060355040a0c025a33020101300d06092a864886f70d01010b05000481804526fd4ce18455902077a9dafa6c028cc26218b400b5ac0f8ec85fef4752b7736c609d19b1d3fb935609681b9cf5b8e473af29d2de8694f6d0518b9ac24ed45954bb1f3eeab70a4624d3c5a4d0311a354d4348547bf4e0202a73c1a80cb334ef99b855c7ea384aa6d57e708c439a93c8859da1ecdaa2c36ea26b7a6b1b7f33e6";

// ======= TEST ===============================================================

test("attr ContentType tSTInfo", function() {
var o = new KJUR.asn1.cms.ContentType({type: "1.2.840.113549.1.9.16.1.4"});
equal(o.getEncodedHex(), "301a06092a864886f70d010903310d060b2a864886f70d0109100104", "tstInfo by oid");

var o2 = new KJUR.asn1.cms.ContentType({type: "tstinfo"});
equal(o2.getEncodedHex(), "301a06092a864886f70d010903310d060b2a864886f70d0109100104", "tstInfo by name");
});

test("attr MessageDigest 01020304abcd", function() {
  var o = new KJUR.asn1.cms.MessageDigest({"hex": "01020304abcd"});
  equal(o.getEncodedHex(), "301506092a864886f70d0109043108040601020304abcd", "tstInfo");
});

test("attr SigningTime 131231235959Z", function() {
  expect(2);

  var o1 = new KJUR.asn1.cms.SigningTime({"str": "131231235959Z"});
  equal(o1.getEncodedHex(), "301c06092a864886f70d010905310f170d3133313233313233353935395a", "{str:1312...}");

  var o2 = new KJUR.asn1.cms.SigningTime({});
  equal(o2.getEncodedHex().substr(0, 34), 
        "301c06092a864886f70d010905310f170d3133313233313233353935395a".substr(0, 34), "{}");
});

test("attr SigningCertificate z4self", function() {
var hExpect = "3050060b2a864886f70d010910020c3141303f303d303b041476c19d787741bdaf76cab1c42d166cb536aa83f83023301ea41c301a310b3009060355040613025553310b3009060355040a0c025a34020101";
var o = new KJUR.asn1.cms.SigningCertificate({array: [sZ4_CERPEM]});
equal(o.getEncodedHex(), hExpect, "hex [certpem]");
equal(
ASN1HEX.dump(o.getEncodedHex()), 
ASN1HEX.dump(hExpect),
"dump [certpem]");

var hExpect = "302b060b2a864886f70d010910020c311c301a30183016041476c19d787741bdaf76cab1c42d166cb536aa83f8";
var params = {array: [sZ4_CERPEM], hasis: false};
var o = new KJUR.asn1.cms.SigningCertificate(params);
equal(o.getEncodedHex(), hExpect, "hex [certpem]/hasis=false");
equal(
ASN1HEX.dump(o.getEncodedHex()), 
ASN1HEX.dump(hExpect),
"dump [certpem]/hasis=false");

var hExpect = "302b060b2a864886f70d010910020c311c301a30183016041476c19d787741bdaf76cab1c42d166cb536aa83f8";
var params = {array: [{cert: sZ4_CERPEM, hasis: false}]};
var o = new KJUR.asn1.cms.SigningCertificate(params);
equal(o.getEncodedHex(), hExpect, "hex [{cert,hasis=false}]");
equal(
ASN1HEX.dump(o.getEncodedHex()), 
ASN1HEX.dump(hExpect),
"dump [{cert,hasis=false}]");

});

// ----- ESSCertID -----
test("ESSCertID test", function() {
var _ESSCertID = KJUR.asn1.cms.ESSCertID;

var hExpect = "303b041476c19d787741bdaf76cab1c42d166cb536aa83f83023301ea41c301a310b3009060355040613025553310b3009060355040a0c025a34020101";
var o = new _ESSCertID(sZ4_CERPEM);
equal(o.getEncodedHex(), hExpect, "hex certpem");
equal(
ASN1HEX.dump(o.getEncodedHex()), 
ASN1HEX.dump(hExpect),
"dump certpem");

var hExpect = "303b041476c19d787741bdaf76cab1c42d166cb536aa83f83023301ea41c301a310b3009060355040613025553310b3009060355040a0c025a34020101";
var o = new _ESSCertID({cert: sZ4_CERPEM});
equal(o.getEncodedHex(), hExpect, "hex params=cert");
equal(
ASN1HEX.dump(o.getEncodedHex()), 
ASN1HEX.dump(hExpect),
"dump params=cert");

var hExpect = "303b041476c19d787741bdaf76cab1c42d166cb536aa83f83023301ea41c301a310b3009060355040613025553310b3009060355040a0c025a34020101";
var params = {
  hash: "76c19d787741bdaf76cab1c42d166cb536aa83f8",
  issuer: {str: "/C=US/O=Z4"},
  serial: {hex: "01"}
};
var o = new _ESSCertID(params);
equal(o.getEncodedHex(), hExpect, "hex params=hash/issuer/serial");
equal(
ASN1HEX.dump(o.getEncodedHex()), 
ASN1HEX.dump(hExpect),
"dump params=hash/issuer/serial");

var hExpect = "3016041476c19d787741bdaf76cab1c42d166cb536aa83f8";
var o = new _ESSCertID({cert: sZ4_CERPEM, hasis: false});
equal(o.getEncodedHex(), hExpect, "hex params=cert/hasis=false");
equal(
ASN1HEX.dump(o.getEncodedHex()), 
ASN1HEX.dump(hExpect),
"dump params=cert/hasis=false");

var hExpect = "3016041476c19d787741bdaf76cab1c42d166cb536aa83f8";
var params = {
  hash: "76c19d787741bdaf76cab1c42d166cb536aa83f8"
};
var o = new _ESSCertID(params);
equal(o.getEncodedHex(), hExpect, "hex params=hash");
equal(
ASN1HEX.dump(o.getEncodedHex()), 
ASN1HEX.dump(hExpect),
"dump params=hash");

});

test("attr SigningCertificateV2 z4self", function() {
var _SigningCertificateV2 = KJUR.asn1.cms.SigningCertificateV2;

var hExpect = "30818b060b2a864886f70d010910022f317c307a30783076300d06096086480165030402030500044026b07a87ff25e74b6a9115ca502a1c913f8f8ee92285418cdfb3c35e910bf30838c98ded14349b8641ce5287616bb0a493e20ee27ac4c377f797dcfcb70fc8c53023301ea41c301a310b3009060355040613025553310b3009060355040a0c025a34020101";
var params = {array: [sZ4_CERPEM], alg: 'sha512'};
var o = new _SigningCertificateV2(params);
equal(o.getEncodedHex(), hExpect, "hex [certpem]/alg512");
equal(ASN1HEX.dump(o.getEncodedHex()), ASN1HEX.dump(hExpect), "dump [certpem]/alg512");

var hExpect = "3037060b2a864886f70d010910022f31283026302430220420c355dc4ee1dca2a95053ed90d27ff13025c887824da7d7cc83348ab2a0e94442";
var params = {array: [sZ4_CERPEM], hasis: false};
var o = new _SigningCertificateV2(params);
equal(o.getEncodedHex(), hExpect, "hex [certpem]/hasis=false");
equal(ASN1HEX.dump(o.getEncodedHex()),
ASN1HEX.dump(hExpect),
"dump [certpem]/hasis=false");

});

// ----- ESSCertIDv2 -----

test("ESSCertIDv2 test", function() {
var _ESSCertIDv2 = KJUR.asn1.cms.ESSCertIDv2;

var hExpect = "30470420c355dc4ee1dca2a95053ed90d27ff13025c887824da7d7cc83348ab2a0e944423023301ea41c301a310b3009060355040613025553310b3009060355040a0c025a34020101";
var o = new _ESSCertIDv2(sZ4_CERPEM);
equal(o.getEncodedHex(), hExpect, "hex certpem");
equal(
ASN1HEX.dump(o.getEncodedHex()), 
ASN1HEX.dump(hExpect),
"dump certpem");

var hExpect = "30470420c355dc4ee1dca2a95053ed90d27ff13025c887824da7d7cc83348ab2a0e944423023301ea41c301a310b3009060355040613025553310b3009060355040a0c025a34020101";
var o = new _ESSCertIDv2({cert: sZ4_CERPEM});
equal(o.getEncodedHex(), hExpect, "hex params=cert");
equal(
ASN1HEX.dump(o.getEncodedHex()), 
ASN1HEX.dump(hExpect),
"dump params=cert");

var hExpect = "30470420c355dc4ee1dca2a95053ed90d27ff13025c887824da7d7cc83348ab2a0e944423023301ea41c301a310b3009060355040613025553310b3009060355040a0c025a34020101";
var params = {
  hash: "c355dc4ee1dca2a95053ed90d27ff13025c887824da7d7cc83348ab2a0e94442",
  issuer: {str: "/C=US/O=Z4"},
  serial: {hex: "01"}
};
var o = new _ESSCertIDv2(params);
equal(o.getEncodedHex(), hExpect, "hex params=hash/issuer/serial");
equal(
ASN1HEX.dump(o.getEncodedHex()), 
ASN1HEX.dump(hExpect),
"dump params=hash/issuer/serial");

var hExpect = "30220420c355dc4ee1dca2a95053ed90d27ff13025c887824da7d7cc83348ab2a0e94442";
var o = new _ESSCertIDv2({cert: sZ4_CERPEM, hasis: false});
equal(o.getEncodedHex(), hExpect, "hex params=cert/hasis=false");
equal(
ASN1HEX.dump(o.getEncodedHex()), 
ASN1HEX.dump(hExpect),
"dump params=cert/hasis=false");

var hExpect = "30220420c355dc4ee1dca2a95053ed90d27ff13025c887824da7d7cc83348ab2a0e94442";
var params = {
  hash: "c355dc4ee1dca2a95053ed90d27ff13025c887824da7d7cc83348ab2a0e94442"
};
var o = new _ESSCertIDv2(params);
equal(o.getEncodedHex(), hExpect, "hex params=hash");
equal(
ASN1HEX.dump(o.getEncodedHex()), 
ASN1HEX.dump(hExpect),
"dump params=hash");

var hExpect = "3051300d06096086480165030402030500044026b07a87ff25e74b6a9115ca502a1c913f8f8ee92285418cdfb3c35e910bf30838c98ded14349b8641ce5287616bb0a493e20ee27ac4c377f797dcfcb70fc8c5";
var o = new _ESSCertIDv2({cert: sZ4_CERPEM, alg: "sha512", hasis: false});
equal(o.getEncodedHex(), hExpect, "hex params=cert/alg512/hasis=false");
equal(
ASN1HEX.dump(o.getEncodedHex()), 
ASN1HEX.dump(hExpect),
"dump params=cert/alg512/hasis=false");

var hExpect = "3051300d06096086480165030402030500044026b07a87ff25e74b6a9115ca502a1c913f8f8ee92285418cdfb3c35e910bf30838c98ded14349b8641ce5287616bb0a493e20ee27ac4c377f797dcfcb70fc8c5";
var o = new _ESSCertIDv2({
  hash: "26b07a87ff25e74b6a9115ca502a1c913f8f8ee92285418cdfb3c35e910bf30838c98ded14349b8641ce5287616bb0a493e20ee27ac4c377f797dcfcb70fc8c5", 
  alg: "sha512"
});
equal(o.getEncodedHex(), hExpect, "hex params=hash/alg512");
equal(
ASN1HEX.dump(o.getEncodedHex()), 
ASN1HEX.dump(hExpect),
"dump params=hash/alg512");

var hExpect = "3076300d06096086480165030402030500044026b07a87ff25e74b6a9115ca502a1c913f8f8ee92285418cdfb3c35e910bf30838c98ded14349b8641ce5287616bb0a493e20ee27ac4c377f797dcfcb70fc8c53023301ea41c301a310b3009060355040613025553310b3009060355040a0c025a34020101";
var o = new _ESSCertIDv2({cert: sZ4_CERPEM, alg: "sha512"});
equal(o.getEncodedHex(), hExpect, "hex params=cert/alg512");
equal(
ASN1HEX.dump(o.getEncodedHex()), 
ASN1HEX.dump(hExpect),
"dump params=cert/alg512");

});

// ----- IssuerSerial -----
test("IssuerSerial /C=US/O=T1 3", function() {
var o = new KJUR.asn1.cms.IssuerSerial({"issuer": {"str": "/C=US/O=T1"},
                                        "serial": {"int": 3}});
equal(
o.getEncodedHex(), 
"3023301ea41c301a310b3009060355040613025553310b3009060355040a0c025431020103",
"by issuer and serial");
//equal(ASN1HEX.dump(o.getEncodedHex()), null, "IGNORE dump check only");

var o2 = new KJUR.asn1.cms.IssuerSerial({cert: sZ4_CERPEM});
equal(o2.getEncodedHex(),
"3023301ea41c301a310b3009060355040613025553310b3009060355040a0c025a34020101",
"by cert");
//equal(ASN1HEX.dump(o2.getEncodedHex()), null, "IGNORE dump check only");
});

// ----- SignerIdentifier ----------

test("SignerIdentifier test", function() {
var _SignerIdentifier = KJUR.asn1.cms.SignerIdentifier;

var hExpect = "301f301a310b3009060355040613025553310b3009060355040a0c025431020103";
var params = {type:"isssn", issuer: {"str": "/C=US/O=T1"}, serial: {"int": 3}}
var o = new _SignerIdentifier(params);
equal(o.getEncodedHex(), hExpect, "hex type=isssn,iss=/C=US/O=T1 sn=3");
equal(
ASN1HEX.dump(o.getEncodedHex()),
ASN1HEX.dump(hExpect),
"dump type=isssn,iss=/C=US/O=T1 sn=3");

var hExpect2 = "301f301a310b3009060355040613025553310b3009060355040a0c025a34020101";
var params2 = {type:"isssn", cert: sZ4_CERPEM};
var o2 = new _SignerIdentifier(params2);
equal(o2.getEncodedHex(), hExpect2, "hex2 type=isssn cert=z4");
equal(
ASN1HEX.dump(o2.getEncodedHex()),
ASN1HEX.dump(hExpect2),
"dump2 type=isssn cert=z4");

var hExpect3 = "a004040212ab";
var params3 = {type:"skid", skid:"12ab"};
var o3 = new _SignerIdentifier(params3);
equal(o3.getEncodedHex(), hExpect3, "hex3 type=skid skid");
equal(
ASN1HEX.dump(o3.getEncodedHex()),
ASN1HEX.dump(hExpect3),
"dump3 type=skid skid");

var hExpect4 = "a01604140764f4c4c9056eff423fdd05a1953c96ed6a13cd";
var params4 = {type:"skid", cert: sZ4_CERPEM};
var o4 = new _SignerIdentifier(params4);
equal(o4.getEncodedHex(), hExpect4, "hex4 cert");
equal(
ASN1HEX.dump(o4.getEncodedHex()), ASN1HEX.dump(hExpect4), "dump4 cert");

});

// ----- IssuerAndSerialNumber -----

test("IssuerAndSerialNumber /C=US/O=T1 3", function() {
var _IssuerAndSerialNumber = KJUR.asn1.cms.IssuerAndSerialNumber;

var hExpect = "301f301a310b3009060355040613025553310b3009060355040a0c025431020103";
//var hExpect = "030101";
var params = {issuer: {"str": "/C=US/O=T1"}, serial: {"int": 3}}
var o = new _IssuerAndSerialNumber(params);
equal(o.getEncodedHex(), hExpect, "hex iss=/C=US/O=T1 sn=3");
equal(
ASN1HEX.dump(o.getEncodedHex()), ASN1HEX.dump(hExpect), "dump");

var hExpect2 = "301f301a310b3009060355040613025553310b3009060355040a0c025a34020101";
//var hExpect2 = "030101";
var params2 = {cert: sZ4_CERPEM};
var o2 = new KJUR.asn1.cms.IssuerAndSerialNumber(params2);
equal(o2.getEncodedHex(), hExpect2, "hex2 iss=/C=US/O=Z4 sn=1");
equal(
ASN1HEX.dump(o2.getEncodedHex()), ASN1HEX.dump(hExpect2), "dump2");

});

// ----- SubjectKeyIdentifier ---------

test("SubjectKeyIdentifier test", function() {
var _SubjectKeyIdentifier = KJUR.asn1.cms.SubjectKeyIdentifier;

var hExpect = "a004040212ab";
var params = {skid:"12ab"};
var o = new _SubjectKeyIdentifier(params);
equal(o.getEncodedHex(), hExpect, "hex skid");
equal(
ASN1HEX.dump(o.getEncodedHex()), ASN1HEX.dump(hExpect), "dump skid");

var hExpect2 = "a01604140764f4c4c9056eff423fdd05a1953c96ed6a13cd";
var params2 = {cert: sZ4_CERPEM};
var o2 = new _SubjectKeyIdentifier(params2);
equal(o2.getEncodedHex(), hExpect2, "hex cert");
equal(
ASN1HEX.dump(o2.getEncodedHex()), ASN1HEX.dump(hExpect2), "dump cert");

});

// ----- AttributeList ----------------

test("AttributeList/1 sorted", function() {
var _AttributeList = KJUR.asn1.cms.AttributeList;
var hExpect = "3141301a06092a864886f70d010903310d060b2a864886f70d0109100104302306092a864886f70d010904311604140102030405060708090001020304050607080900";
var params = {
  array: [{
    attr: "contentType",
    type: "1.2.840.113549.1.9.16.1.4"
  },{
    attr: "messageDigest",
    hex: "0102030405060708090001020304050607080900"
  }],
  sortflag: true
};
equal(
(new _AttributeList(params)).getEncodedHex(),
hExpect,
"hex1");

var hExpect2 = "3141301a06092a864886f70d010903310d060b2a864886f70d0109100104302306092a864886f70d010904311604140102030405060708090001020304050607080900";
var params2 = {
  array: [{
    attr: "messageDigest",
    hex: "0102030405060708090001020304050607080900"
  },{
    attr: "contentType",
    type: "1.2.840.113549.1.9.16.1.4"
  }],
  sortflag: true
};
equal(
(new _AttributeList(params2)).getEncodedHex(),
hExpect2,
"hex2");

var hExpect3 = "3141302306092a864886f70d010904311604140102030405060708090001020304050607080900301a06092a864886f70d010903310d060b2a864886f70d0109100104";
var params3 = {
  array: [{
    attr: "messageDigest",
    hex: "0102030405060708090001020304050607080900"
  },{
    attr: "contentType",
    type: "1.2.840.113549.1.9.16.1.4"
  }],
  sortflag: false
};
equal(
(new _AttributeList(params3)).getEncodedHex(),
hExpect3,
"hex3");
equal(
ASN1HEX.dump((new _AttributeList(params3)).getEncodedHex()),
ASN1HEX.dump(hExpect3),
"dump3");

var hExpect4 = "31163014060b2a864886f70d010910020e31053003020101";
var params4 = {
  array: [{
    attr: "signatureTimeStamp",
    tst: "3003020101"
  }],
};
equal(
(new _AttributeList(params4)).getEncodedHex(),
hExpect4,
"hex4 sigTS");
equal(
ASN1HEX.dump((new _AttributeList(params4)).getEncodedHex()),
ASN1HEX.dump(hExpect4),
"dump4 sigTS");

});

// ----- RevocationInfoChoices -----
test("RevocationInfoChoices test", function() {
var hExpect = "a1163003020107a10f06082b060105050710023003020108";
var params = [{crl: "3003020107"},{ocsp: "3003020108"}];
var dObj = new KJUR.asn1.cms.RevocationInfoChoices(params);
equal(dObj.getEncodedHex(), hExpect, "hex [crlhex,ocsp]");
equal(
ASN1HEX.dump(dObj.getEncodedHex()),
ASN1HEX.dump(hExpect),
"dump [crlhex,ocsp]");
});

// ----- RevocationInfoChoice ------
test("RevocationInfoChoice test", function() {
var hExpect = "3003020107";
var params = {crl: "3003020107"};
var dObj = new KJUR.asn1.cms.RevocationInfoChoice(params);
equal(dObj.getEncodedHex(), hExpect, "hex crl hex");
equal(
ASN1HEX.dump(dObj.getEncodedHex()),
ASN1HEX.dump(hExpect),
"dump crl hex");

var hExpect2 = "a10f06082b060105050710023003020108";
var params2 = {ocsp: "3003020108"};
var dObj2 = new KJUR.asn1.cms.RevocationInfoChoice(params2);
equal(dObj2.getEncodedHex(), hExpect2, "hex ocsp");
equal(
ASN1HEX.dump(dObj2.getEncodedHex()),
ASN1HEX.dump(hExpect2),
"dump ocsp");

});

// ----- OtherRevocationFormat -----
test("OtherRevocationFormat test", function() {
var hExpect = "301206082b060105050710023006020107020108";
var params = {ocsp: "3006020107020108"};
var dObj = new KJUR.asn1.cms.OtherRevocationFormat(params);
equal(dObj.getEncodedHex(), hExpect, "hex");
equal(
ASN1HEX.dump(dObj.getEncodedHex()),
ASN1HEX.dump(hExpect),
"dump");

});

// ----- SignerInfo ----------------

test("SignerInfo/1", function() {
var _SignerInfo = KJUR.asn1.cms.SignerInfo;
var hExpect = "3081a1020101301f301a310b3009060355040613025553310b3009060355040a0c025431020101300906052b0e03021a0500a03f301806092a864886f70d010903310b06092a864886f70d010701302306092a864886f70d01090431160414a1a2a3a4a5a6a7a8a9a0a1a2a3a4a5a6a7a8a9a0300d06092a864886f70d01010505000420b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8";
var params = {
  version: 1,
  id: {type: 'isssn', issuer: {str: '/C=US/O=T1'}, serial: {int: 1}},
  hashalg: "sha1",
  sattrs: {array: [{
    attr: "contentType",
    type: '1.2.840.113549.1.7.1'
  },{
    attr: "messageDigest",
    hex: 'a1a2a3a4a5a6a7a8a9a0a1a2a3a4a5a6a7a8a9a0'
  }]},
  sigalg: "SHA1withRSA",
  sighex: 'b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8'
};
equal(
(new _SignerInfo(params)).getEncodedHex(), hExpect, "hex1");
equal(
ASN1HEX.dump((new _SignerInfo(params)).getEncodedHex()),
ASN1HEX.dump(hExpect),
"dump1");
});

test("SignerInfo/2 sign(sZ4PRV), setSignerIdentifier(sZ4CER)", function() {
var _SignerInfo = KJUR.asn1.cms.SignerInfo;
var hExpect = "30820183020101301f301a310b3009060355040613025553310b3009060355040a0c025a34020101300906052b0e03021a0500a03f301806092a864886f70d010903310b06092a864886f70d010701302306092a864886f70d01090431160414a1a2a3a4a5a6a7a8a9a0a1a2a3a4a5a6a7a8a9a0300d06092a864886f70d010105050004820100dddd5f91e66958996fa1783907bbe97dcb1b1592a4513b0fd6714875dce9957641c4c73cc8d87b9243c83b8f0499fa8392d43721eece8c7aa12e991db721268c290b3fbe930934ecf9c512db5084d55605e6e46c0beb88e784d3bbb60fc7ebaa16e2accdc9d8bef1a1df7c59d7efe2abb0fad8578019f51bea27e205207d42d96c21d19eb276b1744ea751e8357053c6b84452ff97fa4b74b8d3b923edfb2d5a1a5f5ba3e2ecdc63d82f95f416b70e85f2d72acffaea5e16782fa2e202649ecc6c3cc9517b6352500c366a76d71fdbfc9e0195bbef142557d1e211d75a5362d0409002acb576dee3e9f26336a3ebcbfe2642a0fd65c9a22b826fca791b253bdf";
var params = {
  version: 1,
  id: {type: 'isssn', cert: sZ4_CERPEM},
  hashalg: "sha1",
  sattrs: {array: [{
    attr: "contentType",
    type: '1.2.840.113549.1.7.1'
  },{
    attr: "messageDigest",
    hex: 'a1a2a3a4a5a6a7a8a9a0a1a2a3a4a5a6a7a8a9a0'
  }]},
  sigalg: "SHA1withRSA",
  signkey: sZ4_PRVP8PPEM
};
equal(
(new _SignerInfo(params)).getEncodedHex(), hExpect, "hex1");
equal(
ASN1HEX.dump((new _SignerInfo(params)).getEncodedHex()),
ASN1HEX.dump(hExpect),
"dump1");
});

test("EncapsulatedContentInfo test", function() {
var _EncapsulatedContentInfo = KJUR.asn1.cms.EncapsulatedContentInfo;

var hExpect = "301206092a864886f70d010701a0050403616161";
var params = {
  type: "data",
  content: {hex: "616161"}
};
equal(
(new _EncapsulatedContentInfo(params)).getEncodedHex(),
hExpect,
"hex1 content=616161");
equal(
ASN1HEX.dump((new _EncapsulatedContentInfo(params)).getEncodedHex()),
ASN1HEX.dump(hExpect),
"dump1 content=616161");

var hExpect2 = "301206092a864886f70d010701a0050403616161";
var params2 = {
  type: "data",
  content: {str: "aaa"}
};
equal(
(new _EncapsulatedContentInfo(params2)).getEncodedHex(),
hExpect2,
"hex2 content=aaa");
equal(
ASN1HEX.dump((new _EncapsulatedContentInfo(params2)).getEncodedHex()),
ASN1HEX.dump(hExpect2),
"dump2 content=aaa");

var hExpect3 = "300b06092a864886f70d010701";
var params3 = {
  type: "data",
  content: {str: "aaa"},
  isDetached: true
};
equal(
(new _EncapsulatedContentInfo(params3)).getEncodedHex(),
hExpect3,
"hex3 content=aaa detached");
equal(
ASN1HEX.dump((new _EncapsulatedContentInfo(params3)).getEncodedHex()),
ASN1HEX.dump(hExpect3),
"dump3 content=aaa detached");

var hExpect4 = "3019060b2a864886f70d0109100104a00a04083006020101020102";
var params4 = {
  type: "tstinfo",
  content: {hex: '3006020101020102'}
};
equal(
(new _EncapsulatedContentInfo(params4)).getEncodedHex(),
hExpect4,
"hex4 tstInfo content=3006...");
equal(
ASN1HEX.dump((new _EncapsulatedContentInfo(params4)).getEncodedHex()),
ASN1HEX.dump(hExpect4),
"dump4 tstInfo content=3006...");
});

test("ContentInfo/1", function() {
  var nA = KJUR.asn1;
  var seq = new nA.DERSequence({array: [new nA.DERInteger({int: 1}),
                                        new nA.DERInteger({int: 2})]});
  var o = new KJUR.asn1.cms.ContentInfo({type: 'signed-data', obj: seq});
  equal(o.getEncodedHex(), "301506092a864886f70d010702a0083006020101020102");
});

test("SignedData/1 fixed simple", function() {
var _SignedData = KJUR.asn1.cms.SignedData;
var hExpect = "3081b9020101310b300906052b0e03021a0500301206092a864886f70d010701a005040361616131819230818f020101301f301a310b3009060355040613025553310b3009060355040a0c025431020101300906052b0e03021a0500a02d301106092a864886f70d01090431040402abcd301806092a864886f70d010903310b06092a864886f70d010701300d06092a864886f70d01010505000420b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8";
var params = {
  version: 1,
  hashalgs: ["sha1"],
  econtent: {
    type: "data",
    content: {
      hex: "616161"
    }
  },
  sinfos: [{
    version: 1,
    id: {type:'isssn', issuer: {str: '/C=US/O=T1'}, serial: {int: 1}},
    hashalg: "sha1",
    sattrs: {array: [{
      attr: "contentType",
      type: '1.2.840.113549.1.7.1'
    },{
      attr: "messageDigest",
      hex: 'abcd'
    }]},
    sigalg: "SHA1withRSA",
    sighex: 'b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8'
  }],
  fixed: true
};
equal(
(new _SignedData(params)).getEncodedHex(), hExpect, "hex1");
equal(
ASN1HEX.dump((new _SignedData(params)).getEncodedHex()),
ASN1HEX.dump(hExpect),
"dump1");
});

test("SignedData/1 fixed simple + uattrs[sigTS]", function() {
var _SignedData = KJUR.asn1.cms.SignedData;
var hExpect = "3081d1020101310b300906052b0e03021a0500301206092a864886f70d010701a00504036161613181aa3081a7020101301f301a310b3009060355040613025553310b3009060355040a0c025431020101300906052b0e03021a0500a02d301106092a864886f70d01090431040402abcd301806092a864886f70d010903310b06092a864886f70d010701300d06092a864886f70d01010505000420b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8a1163014060b2a864886f70d010910020e31053003020101";
var params = {
  version: 1,
  hashalgs: ["sha1"],
  econtent: {
    type: "data",
    content: {
      hex: "616161"
    }
  },
  sinfos: [{
    version: 1,
    id: {type:'isssn', issuer: {str: '/C=US/O=T1'}, serial: {int: 1}},
    hashalg: "sha1",
    sattrs: {array: [{
      attr: "contentType",
      type: '1.2.840.113549.1.7.1'
    },{
      attr: "messageDigest",
      hex: 'abcd'
    }]},
    uattrs: {array: [{
      attr: "signatureTimeStamp",
      tst: '3003020101'
    }]},
    sigalg: "SHA1withRSA",
    sighex: 'b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8'
  }],
  fixed: true
};
equal(
(new _SignedData(params)).getEncodedHex(), hExpect, "hex1");
equal(
ASN1HEX.dump((new _SignedData(params)).getEncodedHex()),
ASN1HEX.dump(hExpect),
"dump1");
});

test("SignedData/2 fixed simple", function() {
var _SignedData = KJUR.asn1.cms.SignedData;
var hExpect = "3081dc06092a864886f70d010702a081ce3081cb020101310b300906052b0e03021a0500301206092a864886f70d010701a00504036161613181a43081a1020101301f301a310b3009060355040613025553310b3009060355040a0c025431020101300906052b0e03021a0500a03f301806092a864886f70d010903310b06092a864886f70d010701302306092a864886f70d01090431160414a1a2a3a4a5a6a7a8a9a0a1a2a3a4a5a6a7a8a9a0300d06092a864886f70d01010505000420b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8";
var params = {
  version: 1,
  hashalgs: ["sha1"],
  econtent: {
    type: "data",
    content: {
      hex: "616161"
    }
  },
  sinfos: [{
    version: 1,
    id: {type:'isssn', issuer: {str: '/C=US/O=T1'}, serial: {int: 1}},
    hashalg: "sha1",
    sattrs: {array: [{
      attr: "contentType",
      type: '1.2.840.113549.1.7.1'
    },{
      attr: "messageDigest",
      hex: 'a1a2a3a4a5a6a7a8a9a0a1a2a3a4a5a6a7a8a9a0'
    }]},
    sigalg: "SHA1withRSA",
    sighex: 'b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8b1b2b3b4b5b6b7b8'
  }],
  fixed: true
};
equal(
(new _SignedData(params)).getContentInfoEncodedHex(), hExpect, "hex1");
equal(
ASN1HEX.dump((new _SignedData(params)).getContentInfoEncodedHex()),
ASN1HEX.dump(hExpect),
"dump1");
});

test("SignedData/3 update/sign test", function() {
var _SignedData = KJUR.asn1.cms.SignedData;
var hExpect = "308201fa06092a864886f70d010702a08201eb308201e7020101310f300d06096086480165030402010500301806092a864886f70d010701a00b04096a737273617369676e318201b5308201b1020101301f301a310b3009060355040613025553310b3009060355040a0c025a34020101300d06096086480165030402010500a069301806092a864886f70d010903310b06092a864886f70d010701301c06092a864886f70d010905310f170d3133313233313233353935395a302f06092a864886f70d0109043122042084c24dd1d9f56eb3a07ae4a23445add4facbaed78c89475296ab7954284d9cd4300d06092a864886f70d01010b0500048201002e102927a557ecef796fc36b5d858207e93927343361fe5136ce34e645347765ac5de316190ad57bc96bfdff34d7829c7cb6280470a32c3a3965149aed9f1032f9d4f92cecb5038c19b6f0b0f894e730e138cf2f5a7ce1f239535b829977ce1ad4b2fcf226953edecaabf6a5b7fcd179a5e6bd1b44c1f101341a4ac38f7d2d086c2d00cc3c6ad7fb07525cf7cb766420e5f628c36ddaefb708701666a301bc8f1b9c24ca0e50bf4626648d15b2c9eee1b87453f15ca27f3e0580095947a58bcc3ff685b7c4c2cedb3aefe77a87d8ed57eab22a082220e909088cfb18f951c65a9cd39213f9a7e3a81b13b6137f0283da99e0302a9c27238099e31cb5656e3200";
var params = {
  version: 1,
  hashalgs: ["sha256"],
  econtent: {
    type: "data",
    content: {str: "jsrsasign"}
  },
  sinfos: [{
    version: 1,
    id: {type:'isssn', cert: sZ4_CERPEM},
    hashalg: "sha256",
    sattrs: {array: [{
      attr: "contentType",
      type: "data"
    },{
      attr: "signingTime",
      str: '131231235959Z'
    },{
      attr: "messageDigest",
      hex: '84c24dd1d9f56eb3a07ae4a23445add4facbaed78c89475296ab7954284d9cd4'
    }]},
    sigalg: "SHA256withRSA",
    signkey: sZ4_PRVP8PPEM
  }]
};
equal(
(new _SignedData(params)).getContentInfoEncodedHex(), hExpect, "hex1");
equal(
ASN1HEX.dump((new _SignedData(params)).getContentInfoEncodedHex()),
ASN1HEX.dump(hExpect),
"dump1");
});

test("SignedData/4 update/sign/certs", function() {
var _SignedData = KJUR.asn1.cms.SignedData;
var hExpect = "3082050106092a864886f70d010702a08204f2308204ee020101310f300d06096086480165030402010500301806092a864886f70d010701a00b04096a737273617369676ea0820303308202ff308201e7a003020102020101300d06092a864886f70d0101050500301a310b3009060355040613025553310b3009060355040a0c025a34301e170d3133303832383138323833345a170d3233303832383138323833345a301a310b3009060355040613025553310b3009060355040a0c025a3430820122300d06092a864886f70d01010105000382010f003082010a0282010100df74eaa8b47779e5260ed1d2f3da85de9e0c3fb59faadd998e3de56632e38c2183bf0afd7093653438ae29ba0e0e05224f865d3d66ce88c01f0dc0f394ec40d380c39c414601ffa40d088d49ed99b6a0bb6e721cf3e2921bfa8e19021569acb851cafaa2f0e4ca43b91f19fb394eec269f533fd1f4247f3331003a6338a3607f4bb2ea537abad8dd4eb3ca28551035d73afd3cbc11e4e7404c1496c4f62c05c27c42b14e7e519519630f3b52ed27e0b3c54bd053f2d508bc07e745720458285adca6c55a6759419972ac5c346ee5047f460ddff4346ae06475b0d1fc44b63db80a4c97648dcfeb11e3344f1bce51fec7b9434e86bb405443750f9baec44d564b0203010001a350304e301d0603551d0e041604140764f4c4c9056eff423fdd05a1953c96ed6a13cd301f0603551d230418301680140764f4c4c9056eff423fdd05a1953c96ed6a13cd300c0603551d13040530030101ff300d06092a864886f70d01010505000382010100c7c6a27dcbc6a54c7eda81531665f89cfd16eb76f1f0caaf883ab8034e8ab2a34c3e219e810a7f6f8efe62ba1aaee05a2b3960c016940a656d032c1244432ffbff4fbda64d833e12b55f374ea2f952ae446df86704a469d45e7cc00970c16ced3e5ab93e85c8c49104512b56d6dab927011204246f464bea5284ff41abfd0198db0c7a974d7016b4cf76b90747f3172090a14957e914eac51c3587542de45d34a5fb29ed28d7548bd871ec0768d0126eda359f986b4b3d5563d84b6dad758af2f53785a859b9b300be8159a6ec0b60ff31e9d24f6fd7ea14cac865e9837120da1de22ef52dc1c367cb48512acb5cef7265f71477a977d72891f44e14e5ab482a318201b5308201b1020101301f301a310b3009060355040613025553310b3009060355040a0c025a34020101300d06096086480165030402010500a069301806092a864886f70d010903310b06092a864886f70d010701301c06092a864886f70d010905310f170d3133313233313233353935395a302f06092a864886f70d0109043122042084c24dd1d9f56eb3a07ae4a23445add4facbaed78c89475296ab7954284d9cd4300d06092a864886f70d01010b0500048201002e102927a557ecef796fc36b5d858207e93927343361fe5136ce34e645347765ac5de316190ad57bc96bfdff34d7829c7cb6280470a32c3a3965149aed9f1032f9d4f92cecb5038c19b6f0b0f894e730e138cf2f5a7ce1f239535b829977ce1ad4b2fcf226953edecaabf6a5b7fcd179a5e6bd1b44c1f101341a4ac38f7d2d086c2d00cc3c6ad7fb07525cf7cb766420e5f628c36ddaefb708701666a301bc8f1b9c24ca0e50bf4626648d15b2c9eee1b87453f15ca27f3e0580095947a58bcc3ff685b7c4c2cedb3aefe77a87d8ed57eab22a082220e909088cfb18f951c65a9cd39213f9a7e3a81b13b6137f0283da99e0302a9c27238099e31cb5656e3200";
var params = {
  version: 1,
  hashalgs: ["sha256"],
  econtent: {
    type: "data",
    content: {str: "jsrsasign"}
  },
  certs: [sZ4_CERPEM],
  sinfos: [{
    version: 1,
    id: {type: 'isssn', cert: sZ4_CERPEM},
    hashalg: "sha256",
    sattrs: {array: [{
      attr: "contentType",
      type: "data"
    },{
      attr: "signingTime",
      str: '131231235959Z'
    },{
      attr: "messageDigest",
      hex: '84c24dd1d9f56eb3a07ae4a23445add4facbaed78c89475296ab7954284d9cd4'
    }]},
    sigalg: "SHA256withRSA",
    signkey: sZ4_PRVP8PPEM
  }]
};
equal(
(new _SignedData(params)).getContentInfoEncodedHex(), hExpect, "hex1");
equal(
ASN1HEX.dump((new _SignedData(params)).getContentInfoEncodedHex()),
ASN1HEX.dump(hExpect),
"dump1");
});

test("SignedData/5 sign/certs/revinfos(crl,ocsp)", function() {
var _SignedData = KJUR.asn1.cms.SignedData;
var hExpect = "3082051906092a864886f70d010702a082050a30820506020105310f300d06096086480165030402010500301806092a864886f70d010701a00b04096a737273617369676ea0820303308202ff308201e7a003020102020101300d06092a864886f70d0101050500301a310b3009060355040613025553310b3009060355040a0c025a34301e170d3133303832383138323833345a170d3233303832383138323833345a301a310b3009060355040613025553310b3009060355040a0c025a3430820122300d06092a864886f70d01010105000382010f003082010a0282010100df74eaa8b47779e5260ed1d2f3da85de9e0c3fb59faadd998e3de56632e38c2183bf0afd7093653438ae29ba0e0e05224f865d3d66ce88c01f0dc0f394ec40d380c39c414601ffa40d088d49ed99b6a0bb6e721cf3e2921bfa8e19021569acb851cafaa2f0e4ca43b91f19fb394eec269f533fd1f4247f3331003a6338a3607f4bb2ea537abad8dd4eb3ca28551035d73afd3cbc11e4e7404c1496c4f62c05c27c42b14e7e519519630f3b52ed27e0b3c54bd053f2d508bc07e745720458285adca6c55a6759419972ac5c346ee5047f460ddff4346ae06475b0d1fc44b63db80a4c97648dcfeb11e3344f1bce51fec7b9434e86bb405443750f9baec44d564b0203010001a350304e301d0603551d0e041604140764f4c4c9056eff423fdd05a1953c96ed6a13cd301f0603551d230418301680140764f4c4c9056eff423fdd05a1953c96ed6a13cd300c0603551d13040530030101ff300d06092a864886f70d01010505000382010100c7c6a27dcbc6a54c7eda81531665f89cfd16eb76f1f0caaf883ab8034e8ab2a34c3e219e810a7f6f8efe62ba1aaee05a2b3960c016940a656d032c1244432ffbff4fbda64d833e12b55f374ea2f952ae446df86704a469d45e7cc00970c16ced3e5ab93e85c8c49104512b56d6dab927011204246f464bea5284ff41abfd0198db0c7a974d7016b4cf76b90747f3172090a14957e914eac51c3587542de45d34a5fb29ed28d7548bd871ec0768d0126eda359f986b4b3d5563d84b6dad758af2f53785a859b9b300be8159a6ec0b60ff31e9d24f6fd7ea14cac865e9837120da1de22ef52dc1c367cb48512acb5cef7265f71477a977d72891f44e14e5ab482aa1163003020107a10f06082b060105050710023003020108318201b5308201b1020101301f301a310b3009060355040613025553310b3009060355040a0c025a34020101300d06096086480165030402010500a069301806092a864886f70d010903310b06092a864886f70d010701301c06092a864886f70d010905310f170d3133313233313233353935395a302f06092a864886f70d0109043122042084c24dd1d9f56eb3a07ae4a23445add4facbaed78c89475296ab7954284d9cd4300d06092a864886f70d01010b0500048201002e102927a557ecef796fc36b5d858207e93927343361fe5136ce34e645347765ac5de316190ad57bc96bfdff34d7829c7cb6280470a32c3a3965149aed9f1032f9d4f92cecb5038c19b6f0b0f894e730e138cf2f5a7ce1f239535b829977ce1ad4b2fcf226953edecaabf6a5b7fcd179a5e6bd1b44c1f101341a4ac38f7d2d086c2d00cc3c6ad7fb07525cf7cb766420e5f628c36ddaefb708701666a301bc8f1b9c24ca0e50bf4626648d15b2c9eee1b87453f15ca27f3e0580095947a58bcc3ff685b7c4c2cedb3aefe77a87d8ed57eab22a082220e909088cfb18f951c65a9cd39213f9a7e3a81b13b6137f0283da99e0302a9c27238099e31cb5656e3200";
var params = {
  version: 1,
  hashalgs: ["sha256"],
  econtent: {
    type: "data",
    content: {str: "jsrsasign"}
  },
  certs: [sZ4_CERPEM],
  revinfos: [{crl: "3003020107"},{ocsp: "3003020108"}],
  sinfos: [{
    version: 1,
    id: {type:'isssn', cert: sZ4_CERPEM},
    hashalg: "sha256",
    sattrs: {array: [{
      attr: "contentType",
      type: "data"
    },{
      attr: "signingTime",
      str: '131231235959Z'
    },{
      attr: "messageDigest",
      hex: '84c24dd1d9f56eb3a07ae4a23445add4facbaed78c89475296ab7954284d9cd4'
    }]},
    sigalg: "SHA256withRSA",
    signkey: sZ4_PRVP8PPEM
  }]
};
equal(
(new _SignedData(params)).getContentInfoEncodedHex(), hExpect, "hex1");
equal(
ASN1HEX.dump((new _SignedData(params)).getContentInfoEncodedHex()),
ASN1HEX.dump(hExpect),
"dump1");
});

test("SignedData/6 id=skid/sign", function() {
var _SignedData = KJUR.asn1.cms.SignedData;
var hExpect = "308201f106092a864886f70d010702a08201e2308201de020103310f300d06096086480165030402010500301806092a864886f70d010701a00b04096a737273617369676e318201ac308201a8020103a01604140764f4c4c9056eff423fdd05a1953c96ed6a13cd300d06096086480165030402010500a069301806092a864886f70d010903310b06092a864886f70d010701301c06092a864886f70d010905310f170d3133313233313233353935395a302f06092a864886f70d0109043122042084c24dd1d9f56eb3a07ae4a23445add4facbaed78c89475296ab7954284d9cd4300d06092a864886f70d01010b0500048201002e102927a557ecef796fc36b5d858207e93927343361fe5136ce34e645347765ac5de316190ad57bc96bfdff34d7829c7cb6280470a32c3a3965149aed9f1032f9d4f92cecb5038c19b6f0b0f894e730e138cf2f5a7ce1f239535b829977ce1ad4b2fcf226953edecaabf6a5b7fcd179a5e6bd1b44c1f101341a4ac38f7d2d086c2d00cc3c6ad7fb07525cf7cb766420e5f628c36ddaefb708701666a301bc8f1b9c24ca0e50bf4626648d15b2c9eee1b87453f15ca27f3e0580095947a58bcc3ff685b7c4c2cedb3aefe77a87d8ed57eab22a082220e909088cfb18f951c65a9cd39213f9a7e3a81b13b6137f0283da99e0302a9c27238099e31cb5656e3200";
var params = {
  version: 1,
  hashalgs: ["sha256"],
  econtent: {
    type: "data",
    content: {str: "jsrsasign"}
  },
  sinfos: [{
    version: 1,
    id: {type:'skid', cert: sZ4_CERPEM},
    hashalg: "sha256",
    sattrs: {array: [{
      attr: "contentType",
      type: "data"
    },{
      attr: "signingTime",
      str: '131231235959Z'
    },{
      attr: "messageDigest",
      hex: 'ffff'
    }]},
    sigalg: "SHA256withRSA",
    signkey: sZ4_PRVP8PPEM
  }]
};
equal(
(new _SignedData(params)).getContentInfoEncodedHex(), hExpect, "hex1");
equal(
ASN1HEX.dump((new _SignedData(params)).getContentInfoEncodedHex()),
ASN1HEX.dump(hExpect),
"dump1");
});

test("CMSUtil.newSignedData/1", function() {
var _newSignedData = KJUR.asn1.cms.CMSUtil.newSignedData;
var hExpect = "308201fa06092a864886f70d010702a08201eb308201e7020101310f300d06096086480165030402010500301806092a864886f70d010701a00b04096a737273617369676e318201b5308201b1020101301f301a310b3009060355040613025553310b3009060355040a0c025a34020101300d06096086480165030402010500a069301806092a864886f70d010903310b06092a864886f70d010701301c06092a864886f70d010905310f170d3133313233313233353935395a302f06092a864886f70d0109043122042084c24dd1d9f56eb3a07ae4a23445add4facbaed78c89475296ab7954284d9cd4300d06092a864886f70d01010b0500048201002e102927a557ecef796fc36b5d858207e93927343361fe5136ce34e645347765ac5de316190ad57bc96bfdff34d7829c7cb6280470a32c3a3965149aed9f1032f9d4f92cecb5038c19b6f0b0f894e730e138cf2f5a7ce1f239535b829977ce1ad4b2fcf226953edecaabf6a5b7fcd179a5e6bd1b44c1f101341a4ac38f7d2d086c2d00cc3c6ad7fb07525cf7cb766420e5f628c36ddaefb708701666a301bc8f1b9c24ca0e50bf4626648d15b2c9eee1b87453f15ca27f3e0580095947a58bcc3ff685b7c4c2cedb3aefe77a87d8ed57eab22a082220e909088cfb18f951c65a9cd39213f9a7e3a81b13b6137f0283da99e0302a9c27238099e31cb5656e3200";
var params = {
  version: 1,
  hashalgs: ["sha256"],
  econtent: {
    type: "data",
    content: {str: "jsrsasign"}
  },
  sinfos: [{
    version: 1,
    id: {type:'isssn', cert: sZ4_CERPEM},
    hashalg: "sha256",
    sattrs: {array: [{
      attr: "contentType",
      type: "data"
    },{
      attr: "signingTime",
      str: '131231235959Z'
    },{
      attr: "messageDigest",
      hex: '84c24dd1d9f56eb3a07ae4a23445add4facbaed78c89475296ab7954284d9cd4'
    }]},
    sigalg: "SHA256withRSA",
    signkey: sZ4_PRVP8PPEM
  }]
};
equal(
_newSignedData(params).getContentInfoEncodedHex(),
hExpect,
"hex1");
equal(
ASN1HEX.dump(_newSignedData(params).getContentInfoEncodedHex()),
ASN1HEX.dump(hExpect),
"dump1");
});

test("CMSUtil.newSignedData/2 certificate added", function() {
var _newSignedData = KJUR.asn1.cms.CMSUtil.newSignedData;
var hExpect = "3082050106092a864886f70d010702a08204f2308204ee020101310f300d06096086480165030402010500301806092a864886f70d010701a00b04096a737273617369676ea0820303308202ff308201e7a003020102020101300d06092a864886f70d0101050500301a310b3009060355040613025553310b3009060355040a0c025a34301e170d3133303832383138323833345a170d3233303832383138323833345a301a310b3009060355040613025553310b3009060355040a0c025a3430820122300d06092a864886f70d01010105000382010f003082010a0282010100df74eaa8b47779e5260ed1d2f3da85de9e0c3fb59faadd998e3de56632e38c2183bf0afd7093653438ae29ba0e0e05224f865d3d66ce88c01f0dc0f394ec40d380c39c414601ffa40d088d49ed99b6a0bb6e721cf3e2921bfa8e19021569acb851cafaa2f0e4ca43b91f19fb394eec269f533fd1f4247f3331003a6338a3607f4bb2ea537abad8dd4eb3ca28551035d73afd3cbc11e4e7404c1496c4f62c05c27c42b14e7e519519630f3b52ed27e0b3c54bd053f2d508bc07e745720458285adca6c55a6759419972ac5c346ee5047f460ddff4346ae06475b0d1fc44b63db80a4c97648dcfeb11e3344f1bce51fec7b9434e86bb405443750f9baec44d564b0203010001a350304e301d0603551d0e041604140764f4c4c9056eff423fdd05a1953c96ed6a13cd301f0603551d230418301680140764f4c4c9056eff423fdd05a1953c96ed6a13cd300c0603551d13040530030101ff300d06092a864886f70d01010505000382010100c7c6a27dcbc6a54c7eda81531665f89cfd16eb76f1f0caaf883ab8034e8ab2a34c3e219e810a7f6f8efe62ba1aaee05a2b3960c016940a656d032c1244432ffbff4fbda64d833e12b55f374ea2f952ae446df86704a469d45e7cc00970c16ced3e5ab93e85c8c49104512b56d6dab927011204246f464bea5284ff41abfd0198db0c7a974d7016b4cf76b90747f3172090a14957e914eac51c3587542de45d34a5fb29ed28d7548bd871ec0768d0126eda359f986b4b3d5563d84b6dad758af2f53785a859b9b300be8159a6ec0b60ff31e9d24f6fd7ea14cac865e9837120da1de22ef52dc1c367cb48512acb5cef7265f71477a977d72891f44e14e5ab482a318201b5308201b1020101301f301a310b3009060355040613025553310b3009060355040a0c025a34020101300d06096086480165030402010500a069301806092a864886f70d010903310b06092a864886f70d010701301c06092a864886f70d010905310f170d3133313233313233353935395a302f06092a864886f70d0109043122042084c24dd1d9f56eb3a07ae4a23445add4facbaed78c89475296ab7954284d9cd4300d06092a864886f70d01010b0500048201002e102927a557ecef796fc36b5d858207e93927343361fe5136ce34e645347765ac5de316190ad57bc96bfdff34d7829c7cb6280470a32c3a3965149aed9f1032f9d4f92cecb5038c19b6f0b0f894e730e138cf2f5a7ce1f239535b829977ce1ad4b2fcf226953edecaabf6a5b7fcd179a5e6bd1b44c1f101341a4ac38f7d2d086c2d00cc3c6ad7fb07525cf7cb766420e5f628c36ddaefb708701666a301bc8f1b9c24ca0e50bf4626648d15b2c9eee1b87453f15ca27f3e0580095947a58bcc3ff685b7c4c2cedb3aefe77a87d8ed57eab22a082220e909088cfb18f951c65a9cd39213f9a7e3a81b13b6137f0283da99e0302a9c27238099e31cb5656e3200";
var params = {
  version: 1,
  hashalgs: ["sha256"],
  econtent: {
    type: "data",
    content: {str: "jsrsasign"}
  },
  certs: [sZ4_CERPEM],
  sinfos: [{
    version: 1,
    id: {type:'isssn', cert: sZ4_CERPEM},
    hashalg: "sha256",
    sattrs: {array: [{
      attr: "contentType",
      type: "data"
    },{
      attr: "signingTime",
      str: '131231235959Z'
    },{
      attr: "messageDigest",
      hex: '84c24dd1d9f56eb3a07ae4a23445add4facbaed78c89475296ab7954284d9cd4'
    }]},
    sigalg: "SHA256withRSA",
    signkey: sZ4_PRVP8PPEM
  }]
};
equal(
_newSignedData(params).getContentInfoEncodedHex(),
hExpect,
"hex1");
equal(
ASN1HEX.dump(_newSignedData(params).getContentInfoEncodedHex()),
ASN1HEX.dump(hExpect),
"dump1");
});

test("(19) CMSUtil.newSignedData/3 2+signcertv2,sigpol added", function() {
var _newSignedData = KJUR.asn1.cms.CMSUtil.newSignedData;
var hExpect = "3082059006092a864886f70d010702a08205813082057d020101310f300d06096086480165030402010500301806092a864886f70d010701a00b04096a737273617369676ea0820303308202ff308201e7a003020102020101300d06092a864886f70d0101050500301a310b3009060355040613025553310b3009060355040a0c025a34301e170d3133303832383138323833345a170d3233303832383138323833345a301a310b3009060355040613025553310b3009060355040a0c025a3430820122300d06092a864886f70d01010105000382010f003082010a0282010100df74eaa8b47779e5260ed1d2f3da85de9e0c3fb59faadd998e3de56632e38c2183bf0afd7093653438ae29ba0e0e05224f865d3d66ce88c01f0dc0f394ec40d380c39c414601ffa40d088d49ed99b6a0bb6e721cf3e2921bfa8e19021569acb851cafaa2f0e4ca43b91f19fb394eec269f533fd1f4247f3331003a6338a3607f4bb2ea537abad8dd4eb3ca28551035d73afd3cbc11e4e7404c1496c4f62c05c27c42b14e7e519519630f3b52ed27e0b3c54bd053f2d508bc07e745720458285adca6c55a6759419972ac5c346ee5047f460ddff4346ae06475b0d1fc44b63db80a4c97648dcfeb11e3344f1bce51fec7b9434e86bb405443750f9baec44d564b0203010001a350304e301d0603551d0e041604140764f4c4c9056eff423fdd05a1953c96ed6a13cd301f0603551d230418301680140764f4c4c9056eff423fdd05a1953c96ed6a13cd300c0603551d13040530030101ff300d06092a864886f70d01010505000382010100c7c6a27dcbc6a54c7eda81531665f89cfd16eb76f1f0caaf883ab8034e8ab2a34c3e219e810a7f6f8efe62ba1aaee05a2b3960c016940a656d032c1244432ffbff4fbda64d833e12b55f374ea2f952ae446df86704a469d45e7cc00970c16ced3e5ab93e85c8c49104512b56d6dab927011204246f464bea5284ff41abfd0198db0c7a974d7016b4cf76b90747f3172090a14957e914eac51c3587542de45d34a5fb29ed28d7548bd871ec0768d0126eda359f986b4b3d5563d84b6dad758af2f53785a859b9b300be8159a6ec0b60ff31e9d24f6fd7ea14cac865e9837120da1de22ef52dc1c367cb48512acb5cef7265f71477a977d72891f44e14e5ab482a3182024430820240020101301f301a310b3009060355040613025553310b3009060355040a0c025a34020101300d06096086480165030402010500a081f7301806092a864886f70d010903310b06092a864886f70d010701301c06092a864886f70d010905310f170d3133313233313233353935395a302e060b2a864886f70d010910020f311f301d06042a0304053015300906052b0e03021a05000408b1b2b3b4b5b6b7b8302f06092a864886f70d0109043122042084c24dd1d9f56eb3a07ae4a23445add4facbaed78c89475296ab7954284d9cd4305c060b2a864886f70d010910022f314d304b304930470420c355dc4ee1dca2a95053ed90d27ff13025c887824da7d7cc83348ab2a0e944423023301ea41c301a310b3009060355040613025553310b3009060355040a0c025a34020101300d06092a864886f70d01010b05000482010013c73a7f055ba1e242d300fc9ceae61a6fa56ceea05b5ae2fc2b4508812cecbf07a09ce4670622f58aa89d4465a705dad2c2e284651d0c5add679257ac8f656a661e8dc902c21cab8cb9886333bf427839ce56a3cd71284731e8da566aa543ad2d932a96ff9087775e4f6e2b0f04c7d4d9e8b921c2fe024ba0c9efa8279703e4a3c9baaeb1c9a5f9e10672a81d058b64a81208f5e88fe8b038e648d65a0474283d0660c46fb7636d085abc2d0e39f74e8ad50a9bb233fa43adddf852d23dd79bd0819b68225d3ee5ecfb0eb2a54c4af859d1bdc350443221db5189a5a8b9c92766dae014ec6badb0abcf2e806c071c6a9f7e3f651f39eda28dc5e509516cb359";
var param = {
  version: 1,
  hashalgs: ["sha256"],
  econtent: {type: "data", content: {str: "jsrsasign"}},
  certs: [sZ4_CERPEM],
  sinfos: [{
    version: 1,
    id: {type:'isssn', cert: sZ4_CERPEM},
    hashalg: 'sha256',
    sattrs: {array: [{
      attr: "contentType",
      type: 'data'
    },{
      attr: "signingTime",
      str: '131231235959Z'
    },{
      attr: "messageDigest",
      hex: '84c24dd1d9f56eb3a07ae4a23445add4facbaed78c89475296ab7954284d9cd4'
    },{
      attr: "signingCertificateV2",
      array: [sZ4_CERPEM]
    },{
      attr: "signaturePolicyIdentifier",
      oid: "1.2.3.4.5",
      alg: 'sha1',
      hash: 'b1b2b3b4b5b6b7b8'
    }]},
    sigalg: 'SHA256withRSA',
    signkey: sZ4_PRVP8PPEM
  }]
};

var sd = _newSignedData(param);
equal(sd.getContentInfoEncodedHex(), hExpect, "hex1");
equal(
ASN1HEX.dump(sd.getContentInfoEncodedHex()), 
ASN1HEX.dump(hExpect),
"dump1");
});

test("CMSUtil.newSignedData/4 not detached signature (default)", function() {
var _newSignedData = KJUR.asn1.cms.CMSUtil.newSignedData;
var hExpect = "308201fa06092a864886f70d010702a08201eb308201e7020101310f300d06096086480165030402010500301806092a864886f70d010701a00b04096a737273617369676e318201b5308201b1020101301f301a310b3009060355040613025553310b3009060355040a0c025a34020101300d06096086480165030402010500a069301806092a864886f70d010903310b06092a864886f70d010701301c06092a864886f70d010905310f170d3133313233313233353935395a302f06092a864886f70d0109043122042084c24dd1d9f56eb3a07ae4a23445add4facbaed78c89475296ab7954284d9cd4300d06092a864886f70d01010b0500048201002e102927a557ecef796fc36b5d858207e93927343361fe5136ce34e645347765ac5de316190ad57bc96bfdff34d7829c7cb6280470a32c3a3965149aed9f1032f9d4f92cecb5038c19b6f0b0f894e730e138cf2f5a7ce1f239535b829977ce1ad4b2fcf226953edecaabf6a5b7fcd179a5e6bd1b44c1f101341a4ac38f7d2d086c2d00cc3c6ad7fb07525cf7cb766420e5f628c36ddaefb708701666a301bc8f1b9c24ca0e50bf4626648d15b2c9eee1b87453f15ca27f3e0580095947a58bcc3ff685b7c4c2cedb3aefe77a87d8ed57eab22a082220e909088cfb18f951c65a9cd39213f9a7e3a81b13b6137f0283da99e0302a9c27238099e31cb5656e3200";
var params = {
  version: 1,
  hashalgs: ["sha256"],
  econtent: {
    type: "data",
    content: {str: "jsrsasign"},
    isDetached: false
  },
  sinfos: [{
    version: 1,
    id: {type:'isssn', cert: sZ4_CERPEM},
    hashalg: 'sha256',
    sattrs: {array: [{
      attr: "contentType",
      type: 'data'
    },{
      attr: "signingTime",
      str: '131231235959Z'
    },{
      attr: "messageDigest",
      hex: '84c24dd1d9f56eb3a07ae4a23445add4facbaed78c89475296ab7954284d9cd4'
    }]},
    sigalg: 'SHA256withRSA',
    signkey: sZ4_PRVP8PPEM
  }]
};
var sd = _newSignedData(params);
equal(sd.getContentInfoEncodedHex(), hExpect, "hex1");
equal(
ASN1HEX.dump(sd.getContentInfoEncodedHex()), 
ASN1HEX.dump(hExpect),
"dump1");
});

test("CMSUtil.newSignedData/5 detached signature", function() {
var _newSignedData = KJUR.asn1.cms.CMSUtil.newSignedData;
var hExpect = "308201ed06092a864886f70d010702a08201de308201da020101310f300d06096086480165030402010500300b06092a864886f70d010701318201b5308201b1020101301f301a310b3009060355040613025553310b3009060355040a0c025a34020101300d06096086480165030402010500a069301806092a864886f70d010903310b06092a864886f70d010701301c06092a864886f70d010905310f170d3133313233313233353935395a302f06092a864886f70d0109043122042084c24dd1d9f56eb3a07ae4a23445add4facbaed78c89475296ab7954284d9cd4300d06092a864886f70d01010b0500048201002e102927a557ecef796fc36b5d858207e93927343361fe5136ce34e645347765ac5de316190ad57bc96bfdff34d7829c7cb6280470a32c3a3965149aed9f1032f9d4f92cecb5038c19b6f0b0f894e730e138cf2f5a7ce1f239535b829977ce1ad4b2fcf226953edecaabf6a5b7fcd179a5e6bd1b44c1f101341a4ac38f7d2d086c2d00cc3c6ad7fb07525cf7cb766420e5f628c36ddaefb708701666a301bc8f1b9c24ca0e50bf4626648d15b2c9eee1b87453f15ca27f3e0580095947a58bcc3ff685b7c4c2cedb3aefe77a87d8ed57eab22a082220e909088cfb18f951c65a9cd39213f9a7e3a81b13b6137f0283da99e0302a9c27238099e31cb5656e3200";
var params = {
  version: 1,
  hashalgs: ["sha256"],
  econtent: {
    type: "data",
    content: {str: "jsrsasign"},
    isDetached: true
  },
  sinfos: [{
    version: 1,
    id: {type:'isssn', cert: sZ4_CERPEM},
    hashalg: 'sha256',
    sattrs: {array: [{
      attr: "contentType",
      type: 'data'
    },{
      attr: "signingTime",
      str: '131231235959Z'
    },{
      attr: "messageDigest",
      hex: '84c24dd1d9f56eb3a07ae4a23445add4facbaed78c89475296ab7954284d9cd4'
    }]},
    sigalg: 'SHA256withRSA',
    signkey: sZ4_PRVP8PPEM
  }]
};
var sd = KJUR.asn1.cms.CMSUtil.newSignedData(params);
equal(sd.getContentInfoEncodedHex(), hExpect, "hex1");
equal(
ASN1HEX.dump(sd.getContentInfoEncodedHex()), 
ASN1HEX.dump(hExpect),
"dump1");
});

test("CMSUtil.verifySignedData", function() {
  var result = KJUR.asn1.cms.CMSUtil.verifySignedData({cms: hZ3P7S});
  equal(result.isValid, true, "isValid");  
  equal(result.parse.cmsType, "signedData", "cmsType");
  equal(result.parse.econtent, "616161", "econtent");
  equal(result.parse.certsIdx, 126, "certsIdx");
  equal(result.parse.revinfosIdx, undefined, "revinfosIdx");
  equal(result.parse.signerinfosIdx, 1154, "signerinfosIdx");
  //deepEqual(result.parse.signerInfos, "", "signerInfos");
  //deepEqual(result, "", "result");
});

test("CMSParser.getAttribute signingCertificate", function() {
var parser = new KJUR.asn1.cms.CMSParser();

var hIn = "3050060b2a864886f70d010910020c3141303f303d303b041476c19d787741bdaf76cab1c42d166cb536aa83f83023301ea41c301a310b3009060355040613025553310b3009060355040a0c025a34020101";
var pExpect = {
  attr: "signingCertificate",
  array: [{
    hash: "76c19d787741bdaf76cab1c42d166cb536aa83f8",
    issuer: {
      array: [
        [{type:"C",value:"US",ds:"prn"}],
        [{type:"O",value:"Z4",ds:"utf8"}]
      ],
      str: "/C=US/O=Z4"
    },
    serial: {hex: "01"}
  }]
};
deepEqual(parser.getAttribute(hIn), pExpect, "z4.cer /C=US/O=Z4 sn:01");
//equal(ASN1HEX.dump(hIn), ASN1HEX.dump("020101"), "dmp1");

var hIn = "a08207c3308207bf308205a7a0030201020210406a1417b3309f78ff5de3bc931fc064300d06092a864886f70d01010b05003081b7310b3009060355040613024348311e301c0603550461131556415443482d4348452d3232312e3033322e353733313e303c060355040a133542756e646573616d74206675657220496e666f726d6174696b20756e642054656c656b6f6d6d756e696b6174696f6e202842495429311d301b060355040b1314537769737320476f7665726e6d656e7420504b493129302706035504031320537769737320476f7665726e6d656e7420526567756c61746564204341203032301e170d3139303530373038313730385a170d3232303530373038313730385a3081d8310b3009060355040613024348310d300b06035504070c044265726e311e301c0603550461131556415443482d4348452d3232312e3033322e353733313e303c060355040a0c3542756e646573616d74206675657220496e666f726d6174696b20756e642054656c656b6f6d6d756e696b6174696f6e202842495429311d301b060355040b0c14537769737320476f7665726e6d656e7420504b49311c301a060355040b0c1354696d65205374616d70205365727669636573311d301b06035504030c14537769737320476f7665726e6d656e742054534130820122300d06092a864886f70d01010105000382010f003082010a0282010100c03ebdc580e752ac7c7d295fcd5aa76878ff8581c24cd93966d1735277f45d26da968f85893008cbf23af61e590b7dee26838329f98ba056af360defd6269ef67a5abcb93b888140d712245b3aebcb90989d0d319a12df8990e25b5302b4ab1123fac5217901082a2ee6387be5d1f2f1855bcbe086c2b02afb20ef255d505baebe151a2148075692cc53cd6c1d529a6d35862b5e7caca45e9f4e7d40e212d38ed343b3fded2dfc0ac74884995ef209c014c338464c94d68b2504ca8f47ea7922512b5e4ab2e4ea15b5861e2ce7c89ac7440b7e3271b1a8ee4d3c5ade47e803681676d8e5b23c55f0e88c84b867774d58761f41f67ea0a0a236f140b994a107e30203010001a38202a23082029e30819306082b06010505070103048186308183300a06082b06010505070b023009060704008bec4901023008060604008e460104304b060604008e4601053041303f1639687474703a2f2f7777772e706b692e61646d696e2e63682f6370732f5044532d5347504b495f526567756c617465645f43415f30322e7064661302454e3013060604008e4601063009060704008e46010602300e0603551d0f0101ff04040302078030160603551d250101ff040c300a06082b060105050703083081d60603551d200481ce3081cb3081c806096085740111030502043081ba304306082b060105050702011637687474703a2f2f7777772e706b692e61646d696e2e63682f6370732f4350535f325f31365f3735365f315f31375f335f355f302e706466307306082b0601050507020230670c6554686973206973206120726567756c61746564206365727469666963617465206f662074686520537769737320476f7665726e6d656e7420526567756c617465642043412030322043505320666f722074696d657374616d70696e6720707572706f736573307706082b06010505070101046b3069303906082b06010505073002862d687474703a2f2f7777772e706b692e61646d696e2e63682f6169612f526567756c61746564434130322e637274302c06082b060105050730018620687474703a2f2f7777772e706b692e61646d696e2e63682f6169612f6f637370303e0603551d1f043730353033a031a02f862d687474703a2f2f7777772e706b692e61646d696e2e63682f63726c2f526567756c61746564434130322e63726c301f0603551d23041830168014340bbef2153ea40f5707e241648b3211d1290b61301d0603551d0e04160414e493988ac4bd3720d3b06950adedb7433fac9abe300c0603551d130101ff04023000300d06092a864886f70d01010b0500038202010098a5eb8bb576916f18550d84250c0cbf63976d7b90256ca0e06fcf41908d1320bcd6cdf806ffb6a34653b7a07b988b3a29fc0683a58dcec61dc2cd3ded8ce346f2017ac7d3563ceaaa3b2b5d62c2a6df58b1c58545216e74404ee3f5306f684b06b0a94776afef082fde274775c5e32560b73ce3613b80101d6cbec22f6537c98f443bb03cef12a321ffe44b5453c26d95267dc34f466488cf5f6a6d4fa7ee9cacd3e2d02551fc52cfe6672a281b930106c7a76a12e3be1a8636b024d0b1493bff33ab5a31d316cce684732f6d0438dc5cad2a71b3ead582b2f6085c11e7a70d1b2a0b33a9a37c98af41e47efa8375cb4c74012344e71f743cf4c2a99b3dde0485816553916b731ca9ddafdc0c3eddda821639a157f1c41f0cfb71db0ddd96d949a9b3bfb59886126d816a9096b2a2c2e495c0a8503131d49b2711b5d55e43f40c857ac89387f5884a8d1b1c7340ced06ea2f888653739e76b52292ad486110c2ee5c21240f8792a2b468c21d270144e4cb2b45c3cc31ccdffce5d59f30d24bc9d174d32f5c7a9d7b5df3872c988aa75aee285954a99a456973f5894c4c58dd9fd05054daaa6306f35336392207b72c414e589168a0b13cbd7e3ee26ad5e15478302e6d81df72cfcff982c765d16c91facafc5e599675cc5215c4599316df9a2d5479bd6bf40781134ed61dc59242a1aed0dd4c3068297c6e589aea449a9794c";
var aExp = {array: ["-----BEGIN CERTIFICATE-----\r\nMIIHvzCCBaegAwIBAgIQQGoUF7Mwn3j/XeO8kx/AZDANBgkqhkiG9w0BAQsFADCB\r\ntzELMAkGA1UEBhMCQ0gxHjAcBgNVBGETFVZBVENILUNIRS0yMjEuMDMyLjU3MzE+\r\nMDwGA1UEChM1QnVuZGVzYW10IGZ1ZXIgSW5mb3JtYXRpayB1bmQgVGVsZWtvbW11\r\nbmlrYXRpb24gKEJJVCkxHTAbBgNVBAsTFFN3aXNzIEdvdmVybm1lbnQgUEtJMSkw\r\nJwYDVQQDEyBTd2lzcyBHb3Zlcm5tZW50IFJlZ3VsYXRlZCBDQSAwMjAeFw0xOTA1\r\nMDcwODE3MDhaFw0yMjA1MDcwODE3MDhaMIHYMQswCQYDVQQGEwJDSDENMAsGA1UE\r\nBwwEQmVybjEeMBwGA1UEYRMVVkFUQ0gtQ0hFLTIyMS4wMzIuNTczMT4wPAYDVQQK\r\nDDVCdW5kZXNhbXQgZnVlciBJbmZvcm1hdGlrIHVuZCBUZWxla29tbXVuaWthdGlv\r\nbiAoQklUKTEdMBsGA1UECwwUU3dpc3MgR292ZXJubWVudCBQS0kxHDAaBgNVBAsM\r\nE1RpbWUgU3RhbXAgU2VydmljZXMxHTAbBgNVBAMMFFN3aXNzIEdvdmVybm1lbnQg\r\nVFNBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwD69xYDnUqx8fSlf\r\nzVqnaHj/hYHCTNk5ZtFzUnf0XSbalo+FiTAIy/I69h5ZC33uJoODKfmLoFavNg3v\r\n1iae9npavLk7iIFA1xIkWzrry5CYnQ0xmhLfiZDiW1MCtKsRI/rFIXkBCCou5jh7\r\n5dHy8YVby+CGwrAq+yDvJV1QW66+FRohSAdWksxTzWwdUpptNYYrXnyspF6fTn1A\r\n4hLTjtNDs/3tLfwKx0iEmV7yCcAUwzhGTJTWiyUEyo9H6nkiUSteSrLk6hW1hh4s\r\n58iax0QLfjJxsajuTTxa3kfoA2gWdtjlsjxV8OiMhLhnd01Ydh9B9n6goKI28UC5\r\nlKEH4wIDAQABo4ICojCCAp4wgZMGCCsGAQUFBwEDBIGGMIGDMAoGCCsGAQUFBwsC\r\nMAkGBwQAi+xJAQIwCAYGBACORgEEMEsGBgQAjkYBBTBBMD8WOWh0dHA6Ly93d3cu\r\ncGtpLmFkbWluLmNoL2Nwcy9QRFMtU0dQS0lfUmVndWxhdGVkX0NBXzAyLnBkZhMC\r\nRU4wEwYGBACORgEGMAkGBwQAjkYBBgIwDgYDVR0PAQH/BAQDAgeAMBYGA1UdJQEB\r\n/wQMMAoGCCsGAQUFBwMIMIHWBgNVHSAEgc4wgcswgcgGCWCFdAERAwUCBDCBujBD\r\nBggrBgEFBQcCARY3aHR0cDovL3d3dy5wa2kuYWRtaW4uY2gvY3BzL0NQU18yXzE2\r\nXzc1Nl8xXzE3XzNfNV8wLnBkZjBzBggrBgEFBQcCAjBnDGVUaGlzIGlzIGEgcmVn\r\ndWxhdGVkIGNlcnRpZmljYXRlIG9mIHRoZSBTd2lzcyBHb3Zlcm5tZW50IFJlZ3Vs\r\nYXRlZCBDQSAwMiBDUFMgZm9yIHRpbWVzdGFtcGluZyBwdXJwb3NlczB3BggrBgEF\r\nBQcBAQRrMGkwOQYIKwYBBQUHMAKGLWh0dHA6Ly93d3cucGtpLmFkbWluLmNoL2Fp\r\nYS9SZWd1bGF0ZWRDQTAyLmNydDAsBggrBgEFBQcwAYYgaHR0cDovL3d3dy5wa2ku\r\nYWRtaW4uY2gvYWlhL29jc3AwPgYDVR0fBDcwNTAzoDGgL4YtaHR0cDovL3d3dy5w\r\na2kuYWRtaW4uY2gvY3JsL1JlZ3VsYXRlZENBMDIuY3JsMB8GA1UdIwQYMBaAFDQL\r\nvvIVPqQPVwfiQWSLMhHRKQthMB0GA1UdDgQWBBTkk5iKxL03INOwaVCt7bdDP6ya\r\nvjAMBgNVHRMBAf8EAjAAMA0GCSqGSIb3DQEBCwUAA4ICAQCYpeuLtXaRbxhVDYQl\r\nDAy/Y5dte5AlbKDgb89BkI0TILzWzfgG/7ajRlO3oHuYizop/AaDpY3Oxh3CzT3t\r\njONG8gF6x9NWPOqqOytdYsKm31ixxYVFIW50QE7j9TBvaEsGsKlHdq/vCC/eJ0d1\r\nxeMlYLc842E7gBAdbL7CL2U3yY9EO7A87xKjIf/kS1RTwm2VJn3DT0ZkiM9fam1P\r\np+6crNPi0CVR/FLP5mcqKBuTAQbHp2oS474ahjawJNCxSTv/M6taMdMWzOaEcy9t\r\nBDjcXK0qcbPq1YKy9ghcEeenDRsqCzOpo3yYr0HkfvqDdctMdAEjROcfdDz0wqmb\r\nPd4EhYFlU5Frcxyp3a/cDD7d2oIWOaFX8cQfDPtx2w3dltlJqbO/tZiGEm2BapCW\r\nsqLC5JXAqFAxMdSbJxG11V5D9AyFesiTh/WISo0bHHNAztBuoviIZTc552tSKSrU\r\nhhEMLuXCEkD4eSorRowh0nAUTkyytFw8wxzN/85dWfMNJLydF00y9cep17XfOHLJ\r\niKp1ruKFlUqZpFaXP1iUxMWN2f0FBU2qpjBvNTNjkiB7csQU5YkWigsTy9fj7iat\r\nXhVHgwLm2B33LPz/mCx2XRbJH6yvxeWZZ1zFIVxFmTFt+aLVR5vWv0B4ETTtYdxZ\r\nJCoa7Q3UwwaCl8blia6kSal5TA==\r\n-----END CERTIFICATE-----\r\n"], sortflag: false};
deepEqual(parser.getCertificateSet(hIn), aExp, "set");
});

test("CMSParser.getESSCertIDv2 test", function() {
var parser = new KJUR.asn1.cms.CMSParser();

var hIn = "30470420c355dc4ee1dca2a95053ed90d27ff13025c887824da7d7cc83348ab2a0e944423023301ea41c301a310b3009060355040613025553310b3009060355040a0c025a34020101";
var pExp = {
  alg: "sha256",
  hash: "c355dc4ee1dca2a95053ed90d27ff13025c887824da7d7cc83348ab2a0e94442",
  issuer: {
    array: [
      [{type:"C",value:"US",ds:"prn"}],
      [{type:"O",value:"Z4",ds:"utf8"}]
    ],
    str: "/C=US/O=Z4"
  },
  serial: {hex: "01"}
};
deepEqual(parser.getESSCertIDv2(hIn), pExp, "z4certpem");

var hIn2 = "3051300d06096086480165030402030500044026b07a87ff25e74b6a9115ca502a1c913f8f8ee92285418cdfb3c35e910bf30838c98ded14349b8641ce5287616bb0a493e20ee27ac4c377f797dcfcb70fc8c5";
var pExp2 = {
  hash: "26b07a87ff25e74b6a9115ca502a1c913f8f8ee92285418cdfb3c35e910bf30838c98ded14349b8641ce5287616bb0a493e20ee27ac4c377f797dcfcb70fc8c5",
  alg: "sha512"
};
deepEqual(parser.getESSCertIDv2(hIn2), pExp2, "z4certpem sha512 no-isssn");

var hIn3 = "3076300d06096086480165030402030500044026b07a87ff25e74b6a9115ca502a1c913f8f8ee92285418cdfb3c35e910bf30838c98ded14349b8641ce5287616bb0a493e20ee27ac4c377f797dcfcb70fc8c53023301ea41c301a310b3009060355040613025553310b3009060355040a0c025a34020101";
var pExp3 = {
  hash: "26b07a87ff25e74b6a9115ca502a1c913f8f8ee92285418cdfb3c35e910bf30838c98ded14349b8641ce5287616bb0a493e20ee27ac4c377f797dcfcb70fc8c5",
  alg: "sha512",
  issuer: {
    array: [
      [{type:"C",value:"US",ds:"prn"}],
      [{type:"O",value:"Z4",ds:"utf8"}]
    ],
    str: "/C=US/O=Z4"
  },
  serial: {hex: "01"}
};
deepEqual(parser.getESSCertIDv2(hIn3), pExp3, "z4certpem sha512 isssn");

});

test("CMSParser.getAttribute signingCertificateV2", function() {
var parser = new KJUR.asn1.cms.CMSParser();

var hIn = "30818b060b2a864886f70d010910022f317c307a30783076300d06096086480165030402030500044026b07a87ff25e74b6a9115ca502a1c913f8f8ee92285418cdfb3c35e910bf30838c98ded14349b8641ce5287616bb0a493e20ee27ac4c377f797dcfcb70fc8c53023301ea41c301a310b3009060355040613025553310b3009060355040a0c025a34020101";
var pExp = {
  attr: "signingCertificateV2",
  array: [{
    hash: "26b07a87ff25e74b6a9115ca502a1c913f8f8ee92285418cdfb3c35e910bf30838c98ded14349b8641ce5287616bb0a493e20ee27ac4c377f797dcfcb70fc8c5",
    alg: "sha512",
    issuer: {
      array: [
        [{type:"C",value:"US",ds:"prn"}],
        [{type:"O",value:"Z4",ds:"utf8"}]
      ],
      str: "/C=US/O=Z4"
    },
    serial: {hex: "01"}
  }]
};
deepEqual(parser.getAttribute(hIn), pExp, "z4cert sha512 isssn");

var hIn2 = "3037060b2a864886f70d010910022f31283026302430220420c355dc4ee1dca2a95053ed90d27ff13025c887824da7d7cc83348ab2a0e94442";
var pExp2 = {
  attr: "signingCertificateV2",
  array: [{
    hash: "c355dc4ee1dca2a95053ed90d27ff13025c887824da7d7cc83348ab2a0e94442",
    alg: "sha256"
  }]  
};
deepEqual(parser.getAttribute(hIn2), pExp2, "z4cert sha256 no-isssn");


});

});
-->
</script>
  
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>
<div>
<a href="index.html">TEST INDEX</a> |
<a href="../api/index.html">APIDOCS</a> | 
<a href="qunit-do-asn1.html">asn1</a> | 
<a href="qunit-do-asn1x509.html">asn1x509</a> | 
<a href="qunit-do-asn1cms.html">asn1cms</a> | 
<a href="qunit-do-asn1cades.html">asn1cades</a> | 
<a href="qunit-do-asn1tsp.html">asn1tsp</a> | 
</div>
</body>
</html>

